package com.atguigu.gmall.juc.atomic;

import java.util.concurrent.Semaphore;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/6/2 18:26
 */
public class Simplledemo {
    public static void main(String[] args) {
        Semaphore semaphore = new Semaphore(3);
        for (int i = 1; i <=6 ; i++) {
            new Thread(()->{
                try {
                    semaphore.acquire();
                    System.out.println(Thread.currentThread().getName()+"抢到了");
                    Thread.sleep(3);
                    System.out.println(Thread.currentThread().getName()+"离开了");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    semaphore.release();
                }
            },String.valueOf(i)).start();
        }
    }
}
